﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Mads.CoreDomain
{
  /// <summary>
  /// Represents route stop on station.
  /// </summary>
  [DataContract]
  public class RouteStop : KeyAbstraction
  {
    /// <summary>
    /// Route that the stop belongs to.
    /// </summary>
    public Route Route { get; private set; }

    /// <summary>
    /// Station that is stopped on.
    /// </summary>
    [DataMember]
    public Station Station { get; private set; }

    /// <summary>
    /// Order seatsNumber of the stop in the route.
    /// </summary>
    public uint StationNumber { get; set; }

    /// <summary>
    /// Time from train arrival from start station
    /// to arrival to this station.
    /// Not required.
    /// </summary>
    [DataMember]
    public TimeSpan? ArrivalTime { get; set; }

    /// <summary>
    /// Time from train arrival from start station
    /// to departure from this station.
    /// Not required.
    /// </summary>
    [DataMember]
    public TimeSpan? DepartureTime { get; set; }

    public RouteStop(
      Route route, Station station, uint stationNumber,
      uint? arrivalTimeMinutes, uint? departureTimeMinutes)
    {
      if (route == null)
      {
        throw new ArgumentNullException("route");
      }
      if (station == null)
      {
        throw new ArgumentNullException("station");
      }

      Route = route;
      Station = station;
      StationNumber = stationNumber;
      ArrivalTime = arrivalTimeMinutes.HasValue
        ? new Nullable<TimeSpan>(
          new TimeSpan(0, (int)arrivalTimeMinutes.Value, 0))
        : null;
      DepartureTime = departureTimeMinutes.HasValue
        ? new Nullable<TimeSpan>(
          new TimeSpan(0, (int)departureTimeMinutes.Value, 0))
        : null;
    }
    public RouteStop(uint id)
      : base(id)
    {
    }
  }
}